package com.linsir.template.singlechart;

import com.jfinal.core.Controller;
import com.linsir.config.EovaConst;
import com.linsir.core.menu.config.MenuConfig;
import com.linsir.model.Button;
import com.linsir.model.Menu;
import com.linsir.model.MetaObject;
import com.linsir.model.User;

import java.util.List;

/**
 * @author yuxiaolin
 * @title: SingleChartController
 * @projectName linsir-mu
 * @description:  业务模版：单表图(Grid ref Chart)
 * @date 2021/12/2 2:26 PM
 */

public class SingleChartController extends Controller {
    public void list() {

        String menuCode = this.getPara(0);

        // 获取元数据
        Menu menu = Menu.dao.findByCode(menuCode);
        MenuConfig config = menu.getConfig();
        String objectCode = config.getObjectCode();
        MetaObject object = MetaObject.dao.getByCode(objectCode);
        if (object == null) {
            throw new RuntimeException("元对象不存在,请检查:" + objectCode);
        }

        // 根据权限获取功能按钮
        User user = this.getSessionAttr(EovaConst.USER);
        List<Button> btnList = Button.dao.queryByMenuCode(menuCode, user.getRid());

        // 是否需要显示快速查询
        setAttr("isQuery", MetaObject.dao.isExistQuery(objectCode));

        setAttr("menu", menu);
        setAttr("btnList", btnList);
        setAttr("object", object);

        render("/eova/template/singlechart/list.html");
    }

}
